       IDENTIFICATION DIVISION.
       PROGRAM-ID. ZONEDISTRICT.
       ENVIRONMENT DIVISION.
	   CONFIGURATION SECTION.
	   SOURCE-COMPUTER.
	   OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
	   SELECT OLD-MASTER ASSIGN TO DISK.
	   SELECT NEW-MASTER ASSIGN TO DISK.
	   SELECT TRANS-FILE ASSIGN TO DISK.
	   SELECT SORT-FILE  ASSIGN TO DISK.
	   SELECT WORK-FILE  ASSIGN TO DISK.
       DATA DIVISION.
       FILE SECTION.
       FD OLD-MASTER
	   LABEL RECORDS ARE STANDARD
	   VALUE OF FILE-ID IS "OMASTER.DAT".
       01  OLDREC.
	 02     OPARTNUM      PIC 9(4).
	 02     OPARTNAME     PIC X(10).
	 02     OQUANTITY     PIC 9(5).
       FD  NEW-MASTER
	 LABEL RECORDS ARE STANDARD
	 VALUE OF FILE-ID IS "NMASTER.DAT".
       01  NEWREC.
	 02     NPARTNUM      PIC 9(4).
	 02     NPARTNAME     PIC X(10).
	 02     NQUANTITY     PIC 9(6).
       FD  TRANS-FILE
	 LABEL RECORDS ARE STANDARD
	 VALUE OF FILE-ID IS "TRANS.DAT".
       01  TRANSREC.
	 02     PARTNUM       PIC 9(4).
	 02     TRANSCODE     PIC 9.
	 02     QUANTITY      PIC 9(5).
       SD  WORK-FILE.
       01  WORKREC.
	 02     WPARTNUM      PIC 9(4).
	 02     WPARTNAME     PIC X(10).
	 02     WQUANTITY     PIC 9(5).
       FD SORT-FILE
	 LABEL RECORDS ARE STANDARD
	 VALUE OF FILE-ID IS "SMASTER.DAT".
       01  SORTREC.
	 02     SPARTNUM      PIC 9(4).
	 02     SPARTNAME     PIC X(10).
	 02     SQUANTITY     PIC 9(5).
       WORKING-STORAGE SECTION.
       77 C      PIC X.
       77 CH     PIC 9    VALUE IS 0.
       77 I      PIC 9    VALUE IS 0.
       77 NUM1   PIC 99.
       77 NUM2   PIC 99.
       77 FLAG   PIC 9    VALUE IS 0.
       77 TEMP1  PIC Z(4).
       77 TEMP2  PIC Z(5).
       77 TEMP3  PIC Z(6).

       PROCEDURE DIVISION.
       MAINPARA.
	   IF CH NOT = 5 GO TO MENU.
	   STOP RUN.
       MENU.
	   DISPLAY (1, 1) ERASE.
	   DISPLAY "-------MENU-------".
	   DISPLAY " 1 . . .CREATE TRANS-FILE".
	   DISPLAY " 2 . . .CREATE OLD-MASTER".
	   DISPLAY " 3 . . .UPDATION         ".
	   DISPLAY " 4 . . .REPORT           ".
	   DISPLAY " 5 . . .EXIT             ".
	   MOVE 7 TO LIN.
	   MOVE 1 TO COL.
	   DISPLAY (LIN, COL) " CHOICE : ".
	   ACCEPT CH.
	   IF CH = 1 GO TO TRANS-PARA.
	   IF CH = 2 GO TO OLD-PARA.
	   IF CH = 3 GO TO UPDATEPARA.
	   IF CH = 4 GO TO OUTPARA.
	   GO TO MAINPARA.
       OLD-PARA.
	   DISPLAY (1, 1) ERASE.
	   OPEN OUTPUT OLD-MASTER.
	   MOVE 1 TO LIN.
	   MOVE 15 TO COL.
	   DISPLAY (LIN, COL) " NUMBER OF RECORDS: ".
	   ACCEPT NUM1.
	   DISPLAY "------ OLD-MASTER-FILE DATA ENTRY ------".
	   DISPLAY "----------------------------------------".
	   DISPLAY " PARTNO      PARTNAME          QUANTITY ".
	   DISPLAY "----------------------------------------".
	   MOVE 6 TO LIN.
	   PERFORM ADDOLD VARYING I FROM 1 BY 1 UNTIL I > NUM1.
	   DISPLAY " ".
	   DISPLAY "----------------------------------------".
	   CLOSE OLD-MASTER.
	   SORT WORK-FILE ON ASCENDING KEY WPARTNUM USING
		 OLD-MASTER GIVING SORT-FILE.
	   GO TO WAITPARA.
       ADDOLD.
	   MOVE 3 TO COL.
	   ACCEPT(LIN, COL) OPARTNUM.
	   MOVE 15 TO  COL.
	   ACCEPT(LIN, COL) OPARTNAME.
	   MOVE 34 TO  COL.
	   ACCEPT(LIN, COL) OQUANTITY.
	   ADD 1 TO LIN.
	   WRITE OLDREC.
       TRANS-PARA.
	   DISPLAY (1, 1) ERASE.
	   OPEN OUTPUT TRANS-FILE.
	   MOVE 1 TO LIN.
	   MOVE 5 TO COL.
	   DISPLAY (LIN, COL) " NUMBER OF RECORDS: ".
	   ACCEPT NUM2.
	   DISPLAY "----- TRANS-FILE DATA ENTRY -------".
	   DISPLAY "-----------------------------------".
	   DISPLAY " PARTNO   TRANS-CODE      QUANTITY ".
	   DISPLAY "-----------------------------------".
	   MOVE 6 TO LIN.
	   PERFORM ADDTRANS VARYING I FROM 1 BY 1 UNTIL I > NUM2.
	   DISPLAY " ".
	   DISPLAY "-----------------------------------".
	   CLOSE TRANS-FILE.
	   GO TO WAITPARA.
       ADDTRANS.
	   MOVE 3 TO COL.
	   ACCEPT(LIN, COL) PARTNUM.
	   MOVE 15 TO  COL.
	   ACCEPT(LIN, COL) TRANSCODE.
	   MOVE 30 TO  COL.
	   ACCEPT(LIN, COL) QUANTITY.
	   ADD 1 TO LIN.
	   WRITE TRANSREC.
       UPDATEPARA.
	   OPEN INPUT SORT-FILE OUTPUT NEW-MASTER.
	   GO TO READ-SORT.
       READ-SORT.
	   READ SORT-FILE AT END GO TO CLOSING.
	   GO TO COMP-PARA.
       COMP-PARA.
	   OPEN INPUT TRANS-FILE.
	   GO TO READ-TRANS.
       READ-TRANS.
	   READ TRANS-FILE AT END GO TO CLOSE-TRANS.
	   IF SPARTNUM = PARTNUM
	      IF TRANSCODE = 1
		COMPUTE NQUANTITY = SQUANTITY + QUANTITY
		MOVE SPARTNUM  TO NPARTNUM
		MOVE SPARTNAME TO NPARTNAME
		MOVE 1 TO FLAG
		WRITE NEWREC
		GO TO CLOSE-TRANS
	      ELSE
		COMPUTE NQUANTITY = SQUANTITY - QUANTITY
		MOVE SPARTNUM  TO NPARTNUM
		MOVE SPARTNAME TO NPARTNAME
		MOVE 1 TO FLAG
		WRITE NEWREC
		GO TO CLOSE-TRANS
	   ELSE
		MOVE 0 TO FLAG
		GO TO READ-TRANS.

       CLOSE-TRANS.
	   IF FLAG = 0
	      MOVE SPARTNUM TO NPARTNUM
	      MOVE SPARTNAME TO NPARTNAME
	      MOVE SQUANTITY TO NQUANTITY
	      WRITE NEWREC.
	   CLOSE TRANS-FILE.
	   GO TO READ-SORT.
       CLOSING.
	   CLOSE SORT-FILE.
	   CLOSE NEW-MASTER.
	   GO TO MENU.
       OUTPARA.
	   DISPLAY (1, 1) ERASE.
	   OPEN INPUT SORT-FILE NEW-MASTER.
	   DISPLAY "           -------- REPORT -------".
	   DISPLAY "-------------------------------------------------".
	   DISPLAY " PARTNO   PARTNAME     OLD-BALANCE  NEW-BALANCE  ".
	   DISPLAY "-------------------------------------------------".
	   MOVE 6 TO LIN.
	   GO TO READING.
       RETURNING.
	   DISPLAY " ".
	   DISPLAY "-------------------------------------------------".
	   CLOSE NEW-MASTER.
	   CLOSE SORT-FILE.
	   GO TO WAITPARA.
       READING.
	   READ SORT-FILE AT END GO TO READ-AGAIN.
       READ-AGAIN.
	   READ NEW-MASTER AT END GO TO RETURNING.
	   MOVE SPARTNUM  TO TEMP1.
	   MOVE SQUANTITY TO TEMP2.
	   MOVE NQUANTITY TO TEMP3.
	   DISPLAY " ", TEMP1, "     ", SPARTNAME, "    ", TEMP2,
		   "           ", TEMP3.
	   GO TO READING.
       WAITPARA.
	   ACCEPT C.
	   GO TO MENU.
